<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/9/10
  Time: 16:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>业主管理首页</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/roleManagement.css">
    <script src="${pageContext.request.contextPath}/static/jquery/jquery-3.1.1.js"></script>
    <script src="${pageContext.request.contextPath}/static/jquery/jquery.validate.js"></script>
    <link rel="stylesheet" href="/static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/static/frame/static/css/style.css">
    <link rel="icon" href="/static/frame/static/image/code.png">

    <style>
        .showmessages{
            position: absolute;
            width: 100%;height: 600px;
            margin-top: 100px;
        }
        label.error {
            position: absolute;
            margin-top: 68px;
            margin-left: 480px;
            color: red;
            font-size: 14px;
        }
    </style>
</head>
<body>
<div class="pageall">
    <div class="backphall">
        <div class="titleall">
            <div class="titleph">
                <img src="${pageContext.request.contextPath}/static/images/host1.png" style="width:100%;height:100%;"/>
            </div>
            <div class="titleword">业主管理 >>> 业主列表</div>
        </div>
        <form action="selectHost.do" method="post" id="selectform">
            <input type="text" class="selectbox" name="host_name" placeholder="业主姓名（不输入则查询全部）"/>
            <input type="submit" value="查询" class="selectbutton"/>
        </form>
        <div class="contentall"></div>
    </div>
    <div class="showmessages">
        <table class="layui-table">
            <colgroup>
                <col width="150">
                <col width="150">
                <col width="200">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>业主ID</th>
                <th>用户住所</th>
                <th>姓名</th>
                <th>手机号</th>
                <th>住户人数</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="clear" style="display: none" >
            <script>var arr1=[]</script>
            <c:forEach items="${host}" var="o" varStatus="sta">
                    <tr id="hostorder${sta.count}">
                        <td>${sta.count}</td>
                        <td style="display: none">${o.getHost_id()}</td>
                        <td>${o.getHost_building()}栋${o.getHost_unit()}单元${o.getHost_housenumber()}号</td>
                        <td>${o.getHost_name()}</td>
                        <td>${o.getHost_phone()}</td>
                        <td>${o.getHost_number()}</td>
                        <td><label class="createtime">${o.getHost_createtime()}</label></td>
                        <td>
                            <form method="post">
                                <input  type="button" name="buttonValue" value="修改" onclick="confirm(this,${o.getHost_id()})" style="margin-left:20px;cursor:pointer;width: 60px;height: 30px;background-color: deepskyblue;border: 0px">
                            </form>
                        </td>
                    </tr>
                <script>arr1.push($("#hostorder${sta.count}")[0])</script>
            </c:forEach>
            </tbody>
            <tbody id="biuuu_city_list"></tbody>
        </table>
        <div id="demo20"></div>
    </div>
</div>
</body>
<script src="${pageContext.request.contextPath}/static/frame/layui/layui.js" charset="utf-8"></script>
<script>
    function nodeToString ( node ) {
        var tmpNode = document.createElement( "div" );
        tmpNode.appendChild( node.cloneNode( true ) );
        var str = tmpNode.innerHTML;
        tmpNode = node = null; // prevent memory leaks in IE
        return str;
    }
    function clear(){
        document.getElementById('clear').innerHTML=null;
    }

    layui.use(['carousel', 'laypage','laydate','form','upload','jquery'], function(){
        var carousel = layui.carousel
            ,form = layui.form
            ,$=layui.jquery
            ,upload = layui.upload
            ,laypage = layui.laypage
            ,laydate=layui.laydate

        //常规轮播
        carousel.render({
            elem: '#test1'
            ,arrow: 'always'
        });
        var data1= arr1;
        laypage.render({
            elem: 'demo20'
            ,count: data1.length
            ,jump: function(obj){
                //模拟渲染
                document.getElementById('biuuu_city_list').innerHTML = function(){
                    var arr = []
                        ,thisData = data1.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
                    layui.each(thisData, function(index, item){
                        var itemstr=nodeToString(item);
                        arr.push(itemstr);
                    });
                    clear();
                    return arr.join('');
                }();
            }
        });
    });

    function confirm(e,value){
        $.ajax({
            type:'POST',
            url:"${pageContext.request.contextPath}/updateHostPage.do",
            data:{
                host_id:value,
            },
            dataType:"json",
            success:function(data){
                window.location.href="${pageContext.request.contextPath}/updateHost";
            }
        });
    }

    var w=$(window).width();
    var h=$(window).height();
    $(".pageall").innerHeight(h+"px");
    $(".pageall").innerWidth(w+"px");

    /*
使用jquery validate限制查询表单输入
*/
    /**
     * 时间显示，调整格式
     */
    showtime();
    function showtime() {
        var createtime=$(".createtime");
        createtime.each(function () {
            //调用时间格式转换函数formatDateTime()
            $(this).text(formatDateTime($(this).text()))
        })
   }
    /**
     *
     * 在页面上，转换时间格式
     * @param inputTime
     * @returns {string}
     */
    function formatDateTime(inputTime) {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    };
</script>
</html>
